/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-03-07
 * Time: 19:39
 */
public class main3 {
    public static int binarySearch(int[] array,int key){
        return binarySearchFunc(array,0,array.length - 1,key);
    }
    public static int binarySearchFunc(int[] array,int left,int right,int key){
        if (left > right){
            return -1;
        }
        int mid = (right - left) / 2 + left                                                                  ;
        if (array[mid] > key){
            return binarySearchFunc(array,left,mid - 1,key);
        }else if (array[mid] < key){
            return binarySearchFunc(array,mid + 1,right,key);
        }else{
            return mid;
        }
    }
    public static void main(String[] args) {
        //给定一个有序整型数组, 实现二分查找
        int[] array = {1,2,3,4,5,6,7,8,9};
        System.out.println(binarySearch(array,9));
    }
}
